import { Strategy,StrategyOptions,ExtractJwt } from 'passport-jwt'
import { PassportStrategy } from '@nestjs/passport'
import { InjectModel } from 'nestjs-typegoose'
import { User } from '@libs/db/models/user.model'
import { ReturnModelType } from '@typegoose/typegoose'


export class JwtStrategy extends PassportStrategy(Strategy){
    constructor(
        @InjectModel(User) private userModel:ReturnModelType<typeof User>
    ){
        super({
           jwtFromRequest:ExtractJwt.fromAuthHeaderAsBearerToken(),
           secretOrKey:'adsadmaslk1kljkldjkalsd'
        } as StrategyOptions)
    }
    //拿到客户端拿来的用户名
    async validate(id){
        return await this.userModel.findById(id)
    }
}